﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.VisitorCenterUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import ZLocalization.*;
    import flash.text.*;
    import org.aswing.event.*;
    import Display.aswingui.*;
    import L10n.*;

    public class VisitorsPanel extends JPanel {

        public static const PREPARE:String = "prepare";

        protected const GRID_WIDTH:int = 590;
        protected const IDEAL_HEIGHT:int = 330;

        protected var m_gridHolder:JPanel;
        protected var m_scrollPanel:JPanel;
        protected var m_downButton:JButton;
        protected var m_upButton:JButton;
        private var m_imagePane:AssetPane;
        protected var m_dataArr:Array;
        protected var m_top5Friends:Array;
        protected var m_bottom5Friends:Array;
        protected var m_indexOffset:int;

        public function VisitorsPanel(_arg1:LayoutManager=null){
            if (Global.isVisiting()){
                StatsManager.sample(1000, "dialog", "visitorcenter", "leaderboard", "visitorboard");
            } else {
                StatsManager.sample(1000, "dialog", "visitorcenter", "leaderboard", "ownboard");
            };
            super(new FlowLayout(FlowLayout.CENTER));
            this.init();
        }
        private function compareItems(_arg1:Array, _arg2:Array):int{
            if (_arg1[3] > _arg2[3]){
                return (-1);
            };
            if (_arg1[3] < _arg2[3]){
                return (1);
            };
            return (0);
        }
        protected function init():void{
            var _local2:String;
            var _local3:DisplayObject;
            var _local4:Array;
            var _local1:Object = Global.world.mostFrequentHelpers;
            this.m_dataArr = new Array();
            for (_local2 in _local1) {
                _local4 = _local1[_local2];
                this.m_dataArr.push([_local2, _local4[0], _local4[1], _local4[2]]);
            };
            this.m_dataArr.sort(this.compareItems, Array.NUMERIC);
            this.m_top5Friends = this.m_dataArr.slice(0, 5);
            this.m_bottom5Friends = this.m_dataArr.slice(5, 10);
            _local3 = (new (VisitorCenterDialog.assetDict["inner_undertab"])() as DisplayObject);
            ASwingHelper.setBackground(this, _local3);
            if (this.m_dataArr.length > 0){
                this.append(this.makeFriendGrid(this.m_top5Friends));
                this.append(this.makeScrollBar());
            } else {
                this.append(this.makeAddVisitors());
            };
            this.append(ASwingHelper.horizontalStrut(10));
            this.setPreferredHeight(this.IDEAL_HEIGHT);
        }
        protected function makeAddVisitors():JPanel{
            var _local1:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.CENTER);
            var _local2:AssetPane = ASwingHelper.makeMultilineText(ZLoc.t("Dialogs", "VisitorUI_moreVisitors"), 400, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.CENTER, 16, EmbeddedArt.darkBrownTextColor);
            ASwingHelper.setEasyBorder(_local2, 75);
            _local1.append(_local2);
            ASwingHelper.setEasyBorder(_local1, 0, 117, 0, 118);
            return (_local1);
        }
        protected function makeFriendGrid(_arg1:Array):JPanel{
            var _local2:LocalizationObjectToken;
            var _local5:JPanel;
            var _local6:int;
            var _local7:String;
            var _local8:JPanel;
            var _local9:String;
            var _local10:JLabel;
            var _local11:JLabel;
            var _local12:JPanel;
            var _local13:JPanel;
            var _local14:JLabel;
            var _local15:DisplayObject;
            var _local16:String;
            var _local17:Player;
            var _local18:Sprite;
            if (this.m_gridHolder){
                this.m_gridHolder.removeAll();
            } else {
                this.m_gridHolder = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            };
            this.m_gridHolder.append(ASwingHelper.verticalStrut(10));
            var _local3:int;
            while (_local3 < _arg1.length) {
                _local5 = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT, 3);
                _local6 = _arg1[_local3][3];
                _local2 = ZLoc.tk("Dialogs", "VisitorUI_visit", "", _local6);
                _local7 = ZLoc.t("Dialogs", "VisitorUI_visitortext", {
                    amount:_local6,
                    visit:_local2
                });
                _local8 = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
                _local9 = _arg1[_local3][1];
                if (_arg1[_local3][2] != null){
                    _local9 = ZLoc.t("Dialogs", "VisitorUI_from", {
                        user:_arg1[_local3][1],
                        cityName:_arg1[_local3][2]
                    });
                };
                _local10 = ASwingHelper.makeLabel(_local9, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 16, EmbeddedArt.brownTextColor);
                _local11 = ASwingHelper.makeLabel(_local7, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 14, EmbeddedArt.blueTextColor);
                LocaleHelper.localSetting.JLabel_setFont(_local10, EmbeddedArt.SYSTEM_FONT, 16);
                LocaleHelper.localSetting.JLabel_setForeground(_local10, EmbeddedArt.brownTextColor);
                _local12 = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT);
                _local12.append(_local10);
                _local13 = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT);
                _local13.append(_local11);
                _local8.appendAll(_local12, _local13);
                _local14 = ASwingHelper.makeLabel(String(((_local3 + 1) + this.m_indexOffset)), EmbeddedArt.TITLE_FONT, 36, EmbeddedArt.blueTextColor, JLabel.CENTER);
                _local14.setPreferredWidth(50);
                if ((_local3 % 2) == 0){
                    _local18 = new Sprite();
                    _local18.graphics.beginFill(EmbeddedArt.lightBlueTextColor);
                    _local18.graphics.drawRect(0, 0, 637, 55);
                    _local18.graphics.endFill();
                    ASwingHelper.setBackground(_local5, _local18);
                };
                ASwingHelper.setEasyBorder(_local5, 5, 15, 5, 5);
                _local15 = (new EmbeddedArt.hud_no_profile_pic() as DisplayObject);
                this.m_imagePane = new AssetPane(_local15);
                this.m_imagePane.setPreferredSize(new IntDimension(_local15.width, _local15.height));
                _local16 = (_arg1[_local3][0] as String).substr(1);
                _local17 = Global.player.findFriendById(_local16);
                if (_local17 != null){
                    this.loadImage(this.m_imagePane, _local17);
                } else {
                    if (_local16 == Global.player.snUser.uid){
                        this.loadImageSelf(this.m_imagePane, Global.player.snUser.picture);
                    };
                };
                _local5.appendAll(ASwingHelper.horizontalStrut(10), _local14, this.m_imagePane, _local8);
                _local5.setPreferredWidth(this.GRID_WIDTH);
                this.m_gridHolder.append(_local5);
                _local3++;
            };
            ASwingHelper.prepare(this.m_gridHolder);
            var _local4:int = (this.IDEAL_HEIGHT - this.m_gridHolder.getHeight());
            this.m_gridHolder.append(ASwingHelper.verticalStrut(_local4));
            return (this.m_gridHolder);
        }
        protected function loadImage(_arg1:AssetPane, _arg2:Player):void{
            var imagePane:* = _arg1;
            var tempFriend:* = _arg2;
            LoadingManager.load(tempFriend.snUser.picture, function (_arg1:Event):void{
                imagePane.setAsset((_arg1.target.loader as DisplayObject));
            });
        }
        protected function loadImageSelf(_arg1:AssetPane, _arg2:String):void{
            var imagePane:* = _arg1;
            var picture:* = _arg2;
            LoadingManager.load(picture, function (_arg1:Event):void{
                imagePane.setAsset((_arg1.target.loader as DisplayObject));
            });
        }
        protected function showTop5(_arg1:AWEvent):void{
            this.m_indexOffset = 0;
            this.makeFriendGrid(this.m_top5Friends);
            this.m_upButton.setEnabled(false);
            this.m_downButton.setEnabled(true);
            dispatchEvent(new Event(VisitorsPanel.PREPARE, true));
        }
        protected function showBottom5(_arg1:AWEvent):void{
            this.m_indexOffset = 5;
            this.makeFriendGrid(this.m_bottom5Friends);
            this.m_upButton.setEnabled(true);
            this.m_downButton.setEnabled(false);
            dispatchEvent(new Event(VisitorsPanel.PREPARE, true));
        }
        protected function makeScrollBar():JPanel{
            this.m_scrollPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER, 100);
            ASwingHelper.setBackground(this.m_scrollPanel, (new (VisitorCenterDialog.assetDict["conventionCenter_pagination_border"])() as DisplayObject));
            var _local1:AssetPane = new AssetPane((new (VisitorCenterDialog.assetDict["conventionCenter_pagination_dot"])() as DisplayObject));
            var _local2:JPanel = ASwingHelper.centerElement(_local1);
            this.m_downButton = new JButton();
            this.m_upButton = new JButton();
            this.m_downButton.wrapSimpleButton(new SimpleButton((new (VisitorCenterDialog.assetDict["conventionCenter_pagination_bottom_up"])() as DisplayObject), (new (VisitorCenterDialog.assetDict["conventionCenter_pagination_bottom_over"])() as DisplayObject), (new (VisitorCenterDialog.assetDict["conventionCenter_pagination_bottom_over"])() as DisplayObject), (new (VisitorCenterDialog.assetDict["conventionCenter_pagination_bottom_over"])() as DisplayObject)));
            this.m_upButton.wrapSimpleButton(new SimpleButton((new (VisitorCenterDialog.assetDict["conventionCenter_pagination_top_up"])() as DisplayObject), (new (VisitorCenterDialog.assetDict["conventionCenter_pagination_top_over"])() as DisplayObject), (new (VisitorCenterDialog.assetDict["conventionCenter_pagination_top_over"])() as DisplayObject), (new (VisitorCenterDialog.assetDict["conventionCenter_pagination_top_over"])() as DisplayObject)));
            this.m_upButton.setEnabled(false);
            if (this.m_dataArr.length < 6){
                this.m_downButton.setEnabled(false);
            };
            this.m_upButton.addActionListener(this.showTop5, 0, true);
            this.m_downButton.addActionListener(this.showBottom5, 0, true);
            this.m_scrollPanel.setPreferredHeight(300);
            this.m_scrollPanel.setPreferredWidth(50);
            this.m_scrollPanel.appendAll(ASwingHelper.verticalStrut(-80), this.m_upButton, _local2, this.m_downButton);
            return (this.m_scrollPanel);
        }

    }
}//package Display.VisitorCenterUI 
